package com.gecba.minio;


import com.gecba.minio.properties.MinIoProperties;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@EnableConfigurationProperties(MinIoProperties.class)
@Slf4j
public class MinIoAutoConfiguration {

   @Autowired
   private MinIoProperties minIoProperties;


   @Bean("minioClient")
   public MinioClient minioClient(){
      MinioClient minioClient = MinioClient.builder()
              .endpoint(minIoProperties.getHost(), minIoProperties.getPort(), minIoProperties.getSecure().getValue())
              .credentials(minIoProperties.getAccessKey(), minIoProperties.getSecretKey())
              .build();
      log.info("MinIo start in 【{}://{}:{}】",minIoProperties.getSecure().toString().toLowerCase(),minIoProperties.getHost(),minIoProperties.getPort());
      return minioClient;
   }
}
